'use strict';

stareal
    .controller("PriceComparisonListController", function ($scope, $stateParams, $api, $sce, base64, $state, $alert,localStorageService,$timeout,$lazyLoader) {
        $scope.mypage = 2;
        $scope.sacn_more=true;
        $scope.sacn_more0=true;
        $scope.price_navbar=1;
        var h=$(window).height()-1.5*parseFloat(document.documentElement.style.fontSize)+"px";
        $("#wrapper_container").height(h);
        $scope.switchPricebar=function(index){
            $scope.price_navbar=index;
        }
        // 推荐
        $scope.recommendedgoods = new $lazyLoader("app/good/classifyid", {
            kindid:''
        });
        $scope.recommendedgoods.nextPage();
        // 比价分类
        $api.get("app/good/classifylist",{}, true)
            .then(function(ret){
                $scope.classifylists = ret.data;
                $scope.hotsFUN();
            },function(err){
                $alert.show(err);
            });
        //获取城市
        $scope.localeCityId=localStorageService.get('cityid');
        if( $scope.localeCityId==null||$scope.localeCityId==undefined){
            $api.get("app/city/list")
                .then(function (ret){
                    $scope.cities=ret.data;
                    var  map= new AMap.Map('position_center');
                    //实例化城市
                    var geolocation = null;
                    map.plugin('AMap.Geolocation', function () {
                        geolocation = new AMap.Geolocation({
                            enableHighAccuracy: true,//是否使用高精度定位，默认:true
                            timeout: 10000,          //超过10秒后停止定位，默认：无穷大
                            maximumAge: 0,           //定位结果缓存0毫秒，默认：0
                            convert: true,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                            showButton: true,        //显示定位按钮，默认：true
                            buttonPosition: 'LB',    //定位按钮停靠位置，默认：'LB'，左下角
                            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                            showMarker: true,        //定位成功后在定位到的位置显示点标记，默认：true
                            showCircle: true,        //定位成功后用圆圈表示定位精度范围，默认：true
                            panToLocation: true,     //定位成功后将定位到的位置作为地图中心点，默认：true
                            zoomToAccuracy:true      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                        });
                        map.addControl(geolocation);
                        geolocation.getCurrentPosition(function(status,result){
                            if(status=='complete'){
                                if(result.addressComponent.city!=''&&result.addressComponent.city!=null&&result.addressComponent.city!=undefined){
                                    var arr=result.addressComponent.city.split('市');
                                }else{
                                    var arr=result.addressComponent.province.split('市');
                                }
                                localStorageService.set('longitude',result.position.lng);
                                localStorageService.set('latitude',result.position.lat);
                                localStorageService.set('currentPOSITIONID',arr[0]);
                                for(var i=0;i< $scope.cities.length;i++) {
                                    if ($scope.cities[i].name == arr[0]) {
                                        $("#current_city").html($scope.cities[i].name);
                                        $scope.currentPOSITIONID=$scope.cities[i].name
                                        localStorageService.set('cityid', $scope.cities[i].id);
                                        localStorageService.set('cityname', $scope.cities[i].name);
                                    }
                                }
                                $("#current_ationSHOW").show();
                            }else{
                                $alert.show('定位失败！');
                                $("#current_city").html("全国");
                                localStorageService.set('cityname', "全国");
                                localStorageService.set('cityid','-1');//全国默认
                            }

                        });
                    });
                });
        }else{
            $("#current_city").html(localStorageService.get('cityname'));
        }
        //列表 热门
        $scope.hotsFUN=function(){
            $api.get("app/good/hot",{pageNum:1,pageSize:15,cityid:$scope.localeCityId})
                .then(function (ret) {
                    $scope.goodshot = ret.data  //列表
                    $scope.advancesfun();
                },function(err){
                    $alert.show(err);
                })
        }
        //即将开售  app/good/advance
        $scope.advancesfun=function(){
            $api.get("app/good/advance",{})
                .then(function (ret) {
                    $scope.advance = ret.data  //列表
                    $scope.ranksgood();
                },function(err){
                    $alert.show(err);
                })
        }

        //列表  热门演出
        $scope.completeHotRepertoireRepeat=function(){
            var swiper = new Swiper('#hot_Repertoire_container', {
                slidesPerView: 'auto',
                spaceBetween:0,
                pagination: '.hot_Repertoire-pagination',//分页容器
                observer:true,//修改swiper自己或子元素时，自动初始化swiper

            })
            $timeout(function () {
                swiper.setWrapperTransition(0);
                /**设置位移0 显示第一页 */
                swiper.setWrapperTranslate(0);
            },500)
        }
        $scope.bartotla=function(count){
            // console.log(count);
            if(count==undefined||count==''){
                var bar=(count*10).toFixed(0)/100;
                $scope.barstyle = {
                    "width":'0rem' ,
                }
            }else{
                var bar=(count*10).toFixed(0)/100;
                $scope.barstyle = {
                    "width":bar*2.75+'rem' ,
                }
            }

            return $scope.barstyle;
        }
        //列表  排行榜
        $scope.ranksgood=function(){
            $api.get("app/good/scorelist",{})
                .then(function (ret) {
                    var data=ret.data;
                    for(var i=0;i<data.length;i++){
                        if(i<3){
                            data[i].moreRankShowable=true;
                        }else{
                            data[i].moreRankShowable=false;
                        }
                    }
                    $scope.ranks = data  //列表
                    $scope.rankssalelist();
                },function(err){
                    $alert.show(err);
                })
        }
        //预售  app/good/salelist
        $scope.rankssalelist=function(){
            $api.get("app/good/salelist",{})
                .then(function (ret) {
                    var data=ret.data;
                    for(var i=0;i<data.length;i++){
                        if(i<3){
                            data[i].moreRankShowable=true;
                        }else{
                            data[i].moreRankShowable=false;
                        }
                    }
                    $scope.rankssalelists = data  //列表
                },function(err){
                    $alert.show(err);
                })
        }
        //票务
        //查看10
        $scope.scan_more=function(){
          for(var i=3;i<$scope.ranks.length;i++){
              $scope.ranks[i].moreRankShowable=true;
          }
          $scope.sacn_more=false;
        }
        //收起
        $scope.Takeup=function(){
            for(var i=3;i<$scope.ranks.length;i++){
                $scope.ranks[i].moreRankShowable=false;
            }
            $scope.sacn_more=true;
        }
        //预售
        //查看10
        $scope.scan_more0=function(){
            for(var i=3;i<$scope.ranks.length;i++){
                $scope.rankssalelists[i].moreRankShowable=true;
            }
            $scope.sacn_more0=false;
        }
        //收起
        $scope.Takeup0=function(){
            for(var i=3;i<$scope.ranks.length;i++){
                $scope.rankssalelists[i].moreRankShowable=false;
            }
            $scope.sacn_more0=true;
        }
    });